<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<style>
  .header {
    position: fixed;
    top: 0;
    left: 220px;
    width: calc(100% - 220px);
    height: 62px;
    background-color: #202741;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 1000;
  }

  .header h3 {
    margin-top: 20px;
    font-size: 24px;
    font-weight: bold;
    margin-left: 40px;
  }

  .header-right {
    display: flex;
    align-items: center;
    z-index: 1000;
  }

  .email-icon {
    width: 50px;
    height: 50px;
    margin-right: 10px;
  }

  .email-icon:hover {
    cursor: pointer;
  }

  .user-info {
    display: flex;
    align-items: center;
    margin-right: 40px;
  }

  .dropdown {
    position: relative;
  }

  .dropdown-menu {
    display: none;
    position: absolute;
    background-color: #f9f9f9;
    min-width: 60px;
    box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2);
    z-index: 1;
  }

  .dropdown:hover .dropdown-menu {
    display: block;
  }

  .menu-item {
    color: black;
    padding: 12px 16px;
    font-weight: bold;
    text-decoration: none;
    display: block;
    font-size: 14px;
    z-index: 2;
  }

  .menu-item:hover {
    background-color: #f1f1f1;
  }
</style>

<div class="header">
  <div></div>
  <div class="header-right">
    <img src="./assets/images/邮件.png" alt="邮件" class="email-icon">
    <div class="user-info">
      <div class="dropdown">
        <img src="${user_key.avatar}" style="width: 40px;border-radius:50%;margin: 0 10px" alt="头像">
        <div class="dropdown-menu">
          <a class="menu-item" href="Index.jsp">首页</a>
          <a class="menu-item" href="javascript:void(0)" onclick="handleLogout()">退出</a>
        </div>
      </div>
    </div>
  </div>

</div>

<script>
  function handleLogout() {
    var xhr = new XMLHttpRequest()
    xhr.onload = function () {
      if (xhr.status === 200) {
        window.location.href = "Login.jsp"
      }
    }

    xhr.open("POST", "account?type=2", true)
    xhr.send()
  }
</script>
